package com.example.administrator.myapplication.Model;

import com.example.administrator.myapplication.Bean.AjaxResult;
import com.example.administrator.myapplication.Bean.User;
import com.example.administrator.myapplication.Http.Api;
import com.example.administrator.myapplication.Http.RetrofitHelper;
import com.example.administrator.myapplication.Presenter.ILogonListener;
import com.example.administrator.myapplication.Presenter.IMineListener;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2019/10/8 0008.
 */

public class MineModel implements IMineModel{
    @Override
    public void getProfile(final IMineListener iMineListener) {
        RetrofitHelper retrofitHelper = new RetrofitHelper(Api.Server_Host);
        retrofitHelper.getProfile().enqueue(new Callback<User>() {
            @Override
            public void onResponse(Call<User> call, Response<User> response) {
                iMineListener.profile(response.body());
            }

            @Override
            public void onFailure(Call<User> call, Throwable t) {
                iMineListener.error(t.toString());
            }
        });
    }

    @Override
    public void updateProfile(User user,final IMineListener iMineListener) {
        RetrofitHelper retrofitHelper = new RetrofitHelper(Api.Server_Host);
        retrofitHelper.updateProfile(user).enqueue(new Callback<AjaxResult>() {
            @Override
            public void onResponse(Call<AjaxResult> call, Response<AjaxResult> response) {
                iMineListener.success(response.body());
            }

            @Override
            public void onFailure(Call<AjaxResult> call, Throwable t) {
                iMineListener.error(t.toString());
            }
        });
    }
}
